--﻿ CALC_SILVER_ALTAR_ARGS

-------------------------------
-- 计算银色祭坛参数
-- @param args    dungeon_element.csv表中的args字段
-- @param layer   当前所在的地牢层
return function(args, layer)
    local ret = {};
    local bonus = args.bonus;

    -- 获取地牢难度系数
    local dugeonId = DungeonM.getDungeonId();
    if dugeonId == nil then
        dugeonId = user.dbase:query("currentDungeon");
    end
    local layerFix = DungeonAreaM.query(dugeonId, "layer_fix");
    
    -- 排序（生命和攻击优先）
    local function cmp(bonus1, bonus2)
        if bonus1[2] == "max_hp" or bonus1[2] == "attack" then
            return true;
        else
            return false;
        end
    end
    table.sort(bonus, cmp);

    -- 计算消耗
    local cost;
    local prop;

    -- 获取祭坛连续未出现加攻击的次数
    local noAttackTimes = ME.user.dbase:query("altar_no_attack_times", 0);
    --    ME.user.dbase:set("altar_no_attack_times", times);
    -- 第一层固定为攻击/魔力
    if layer == 1 or noAttackTimes > 3 then

        -- 重置次数
        ME.user.dbase:set("altar_no_attack_times", 0);

        cost = FormulaM.invoke("CALC_SEARCH_POINT_COST", 30, layer, layerFix);
        -- 第一个奖励
        prop = {
            ["bonus"] = { 2, "attack", 1, },
            ["cost"]  = { 2, "search_point", cost, },
        };
        table.insert(ret, prop);

        -- 第二个奖励
        prop = {
            ["bonus"] = { 2, "magic", 1,},
            ["cost"]  = { 2, "search_point", cost, },
        };
        table.insert(ret, prop);
    else
        if bonus[1][2] == "max_hp" or bonus[1][2] == "max_mp" then
            cost = FormulaM.invoke("CALC_SEARCH_POINT_COST", 15, layer, layerFix);
            noAttackTimes = noAttackTimes + 1;
            ME.user.dbase:set("altar_no_attack_times", noAttackTimes);
        else
            cost = FormulaM.invoke("CALC_SEARCH_POINT_COST", 30, layer, layerFix);

            -- 重置次数
            ME.user.dbase:set("altar_no_attack_times", 0);
        end

        -- 第一个奖励
        prop = {
            ["bonus"] = bonus[1],
            ["cost"]  = { 2, "search_point", cost, },
        };
        table.insert(ret, prop);

        -- 第二个奖励
        prop = {
            ["bonus"] = bonus[2],
            ["cost"]  = { 2, "search_point", cost, },
        };
        table.insert(ret, prop);
    end

    return ret;
end